package containerlogistik.implementation;

import containerlogistik.interfaces.Work;

public class WorkInNm extends AbstractValue<Work> implements Work {

    private final double newtonMeter;
    
    private WorkInNm(double newtonMeter) {
        this.newtonMeter = newtonMeter;
    }

    static Work valueOf(double nm) {
        return new WorkInNm(nm);
    }

    @Override
    public double nm() {
        return this.newtonMeter;
    }

    @Override
    public double j() {
        return this.nm();
    }

    @Override
    public double ws() {        
        return this.nm();
    }

    @Override
    public boolean isZero() {
        return (this.equals(Values.ZERO_WORK));
    }

    @Override
    public boolean isValid() {
        return true;
    }

    @Override
    public String toString() {
        return "WorkInNm{" + "nm=" + this.nm() + ", j=" + this.j() + 
                ", ws=" + this.ws() +  '}';
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final WorkInNm other = (WorkInNm) obj;
        if (Double.doubleToLongBits(this.nm()) != Double.doubleToLongBits(other.nm())) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return hashDouble(this.nm());
    }

    @Override
    public int compareTo(Work o) {
        return Double.compare(this.nm(), o.nm());
    }

    @Override
    public Work add(Work value) {
        return Values.workInNm(this.nm() + value.nm());
    }

    @Override
    public Work sub(Work value) {
        return Values.workInNm(this.nm() - value.nm());
    }

    @Override
    public Work mul(double factor) {
        return Values.workInNm(this.nm() * factor);
    }

    @Override
    public Work div(double factor) {
        return Values.workInNm(this.nm() / factor);
    }

    @Override
    public Work inverse() {
        return Values.workInNm(-this.nm());
    }

    @Override
    public double div(Work value) {
        return (this.nm() / value.nm());
    }
}
